package com.ziqing.apeletnews.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.ziqing.apeletnews.R;
import com.ziqing.apeletnews.adapter.ArticleAdapter;
import com.ziqing.apeletnews.adapter.HotAdapter;
import com.ziqing.apeletnews.adapter.ProduceAdapter;
import com.ziqing.apeletnews.base.BaseFragment;
import com.ziqing.apeletnews.bean.ArticleBean;
import com.ziqing.apeletnews.bean.ListBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by WT on 2018/4/12.
 */

public class DiscoveryFragment extends BaseFragment {

    @BindView(R.id.iv_discovery)
    ImageView ivDiscovery;
    @BindView(R.id.rv_hot_chat)
    RecyclerView rvHotChat;
    @BindView(R.id.rv_group)
    RecyclerView rvGroup;
    @BindView(R.id.rv_special)
    RecyclerView rvSpecial;
    Unbinder unbinder;
    @BindView(R.id.rv_hottest)
    RecyclerView rvHottest;

    private HotAdapter adapter;
    private HotAdapter hotAdapter;
    private ArticleAdapter articleAdapter;
    private ProduceAdapter produceAdapter;

    private List<String> data = new ArrayList<>();
    private List<ListBean> data1 = new ArrayList<>();
    private List<String> data2 = new ArrayList<>();
    private List<ArticleBean> data3 = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_discovery, container, false);
        unbinder = ButterKnife.bind(this, view);

        rvHotChat.setNestedScrollingEnabled(false);
        rvGroup.setNestedScrollingEnabled(false);
        rvSpecial.setNestedScrollingEnabled(false);
        initRecycleView();
        Glide.with(getContext())
                .load("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523623154538&di=3bc8b5f3719a10698af3c506c80f1f63&imgtype=0&src=http%3A%2F%2Farticle.fd.zol-img.com.cn%2Ft_s640x2000%2Fg5%2FM00%2F03%2F09%2FChMkJlXSiH-IIvcoAAMM9F4MSHQAAAOcgF48uMAAw0M036.jpg")
                .into(ivDiscovery);

        return view;
    }

    private void initRecycleView() {
        data.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523622354910&di=2b183a3c5f9468d78f29c8daa2842706&imgtype=0&src=http%3A%2F%2Fpic.uzzf.com%2Fup%2F2017-7%2F201707051848359167891.png");
        data.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523622354910&di=2b183a3c5f9468d78f29c8daa2842706&imgtype=0&src=http%3A%2F%2Fpic.uzzf.com%2Fup%2F2017-7%2F201707051848359167891.png");
        data.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523622354910&di=2b183a3c5f9468d78f29c8daa2842706&imgtype=0&src=http%3A%2F%2Fpic.uzzf.com%2Fup%2F2017-7%2F201707051848359167891.png");
        rvHotChat.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        adapter = new HotAdapter(getActivity(), data, R.layout.item_recycle_hotchat);
        rvHotChat.setAdapter(adapter);
        adapter.notifyDataSetChanged();

        data1.add(new ListBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523626897119&di=6e177bbd2bec7db9a088db0de798d7eb&imgtype=0&src=http%3A%2F%2Fg.hiphotos.baidu.com%2Fzhidao%2Fwh%253D450%252C600%2Fsign%3De52b78478444ebf86d246c3becc9fb1c%2F8b82b9014a90f603fdc6dd033a12b31bb051ed04.jpg", "美图收集癖"));
        data1.add(new ListBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523626897119&di=6e177bbd2bec7db9a088db0de798d7eb&imgtype=0&src=http%3A%2F%2Fg.hiphotos.baidu.com%2Fzhidao%2Fwh%253D450%252C600%2Fsign%3De52b78478444ebf86d246c3becc9fb1c%2F8b82b9014a90f603fdc6dd033a12b31bb051ed04.jpg", "聊技术"));
        data1.add(new ListBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523626897119&di=6e177bbd2bec7db9a088db0de798d7eb&imgtype=0&src=http%3A%2F%2Fg.hiphotos.baidu.com%2Fzhidao%2Fwh%253D450%252C600%2Fsign%3De52b78478444ebf86d246c3becc9fb1c%2F8b82b9014a90f603fdc6dd033a12b31bb051ed04.jpg", "电影圈"));
        data1.add(new ListBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523626897119&di=6e177bbd2bec7db9a088db0de798d7eb&imgtype=0&src=http%3A%2F%2Fg.hiphotos.baidu.com%2Fzhidao%2Fwh%253D450%252C600%2Fsign%3De52b78478444ebf86d246c3becc9fb1c%2F8b82b9014a90f603fdc6dd033a12b31bb051ed04.jpg", "扎堆"));
        rvGroup.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        produceAdapter = new ProduceAdapter(getActivity(), data1, R.layout.item_recycle_group);
        rvGroup.setAdapter(produceAdapter);
        produceAdapter.notifyDataSetChanged();

        data2.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523628045471&di=1a9846cf4bd12bcbead16701a084e230&imgtype=0&src=http%3A%2F%2Fe.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F91ef76c6a7efce1b09df0e98a951f3deb58f65e8.jpg");
        data2.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523628045471&di=1a9846cf4bd12bcbead16701a084e230&imgtype=0&src=http%3A%2F%2Fe.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F91ef76c6a7efce1b09df0e98a951f3deb58f65e8.jpg");
        data2.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523628045471&di=1a9846cf4bd12bcbead16701a084e230&imgtype=0&src=http%3A%2F%2Fe.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F91ef76c6a7efce1b09df0e98a951f3deb58f65e8.jpg");
        rvSpecial.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        hotAdapter = new HotAdapter(getActivity(), data2, R.layout.item_recycle_special);
        rvSpecial.setAdapter(hotAdapter);
        hotAdapter.notifyDataSetChanged();

        data3.add(new ArticleBean("","","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523634228476&di=e976c74deefd88dcb515db98415f3cde&imgtype=0&src=http%3A%2F%2Fimage001.server110.com%2F20170322%2F98a96ca05f6e32b15f3c2d0d46e5d051.gif"
                ,"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523634228476&di=e976c74deefd88dcb515db98415f3cde&imgtype=0&src=http%3A%2F%2Fimage001.server110.com%2F20170322%2F98a96ca05f6e32b15f3c2d0d46e5d051.gif",0));
        data3.add(new ArticleBean("","","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523634228476&di=e976c74deefd88dcb515db98415f3cde&imgtype=0&src=http%3A%2F%2Fimage001.server110.com%2F20170322%2F98a96ca05f6e32b15f3c2d0d46e5d051.gif"
                ,"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523634228476&di=e976c74deefd88dcb515db98415f3cde&imgtype=0&src=http%3A%2F%2Fimage001.server110.com%2F20170322%2F98a96ca05f6e32b15f3c2d0d46e5d051.gif",1));
        data3.add(new ArticleBean("","","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523634228476&di=e976c74deefd88dcb515db98415f3cde&imgtype=0&src=http%3A%2F%2Fimage001.server110.com%2F20170322%2F98a96ca05f6e32b15f3c2d0d46e5d051.gif"
                ,"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523634228476&di=e976c74deefd88dcb515db98415f3cde&imgtype=0&src=http%3A%2F%2Fimage001.server110.com%2F20170322%2F98a96ca05f6e32b15f3c2d0d46e5d051.gif",1));
        data3.add(new ArticleBean("","","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523634228476&di=e976c74deefd88dcb515db98415f3cde&imgtype=0&src=http%3A%2F%2Fimage001.server110.com%2F20170322%2F98a96ca05f6e32b15f3c2d0d46e5d051.gif"
                ,"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523634228476&di=e976c74deefd88dcb515db98415f3cde&imgtype=0&src=http%3A%2F%2Fimage001.server110.com%2F20170322%2F98a96ca05f6e32b15f3c2d0d46e5d051.gif",0));
        rvHottest.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false));
        articleAdapter = new ArticleAdapter(data3,getContext());
        rvHottest.setAdapter(articleAdapter);
        adapter.notifyDataSetChanged();
        rvHottest.setFocusable(false);
        rvHottest.setNestedScrollingEnabled(false);
        rvHottest.setHasFixedSize(true);

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
